﻿using System;
using System.IO;

namespace GetWallPagerFromBing
{
    public class SimpleLog
    {
        public static void GetLog(string message)
        {
            Logging(message);
        }

        public static void GetLog(Exception e)
        {
            Logging(e.Message);
        }

        private static void Logging(string logs)
        {
            string logdir_path = Path.Combine(Utils.AppPath, "logs");

            if (!Directory.Exists(logdir_path))
            {
                try
                {
                    Directory.CreateDirectory(logdir_path);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            string logfile_path = Path.Combine(logdir_path, "logfile.txt");

            if (!File.Exists(logfile_path))
            {
                try
                {
                    using (FileStream fs = File.Create(logfile_path))
                    {

                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            using (StreamWriter sw = new StreamWriter(logfile_path, true, System.Text.Encoding.UTF8))
            {
                sw.WriteLine(string.Format("{0}:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), logs));
            }
        }
    }
}
